<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActionController::MimeResponds::Collector</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
<script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Class</span> 
            ActionController::MimeResponds::Collector 
            
                <span class="parent">&lt; 
                    
                    <a href="../../Object.html">Object</a>
                    
                </span>
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../files/actionpack/lib/action_controller/metal/mime_responds_rb.html">actionpack/lib/action_controller/metal/mime_responds.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<p>A container for responses available from the current controller for
requests for different mime-types sent to a particular action.</p>

<p>The public controller methods <code>respond_with</code> and
<code>respond_to</code> may be called with a block that is used to define
responses to different mime-types, e.g. for <code>respond_to</code> :</p>

<pre class="ruby"><span class="ruby-identifier">respond_to</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">format</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">format</span>.<span class="ruby-identifier">html</span>
  <span class="ruby-identifier">format</span>.<span class="ruby-identifier">xml</span> { <span class="ruby-identifier">render</span> <span class="ruby-identifier">xml</span><span class="ruby-operator">:</span> <span class="ruby-ivar">@people</span> }
<span class="ruby-keyword">end</span>
</pre>

<p>In this usage, the argument passed to the block (<code>format</code> above)
is an instance of the <a
href="Collector.html">ActionController::MimeResponds::Collector</a> class.
This object serves as a container in which available responses can be
stored by calling any of the dynamically generated, mime-type-specific
methods such as <code>html</code>, <code>xml</code> etc on the <a
href="Collector.html">Collector</a>. Each response is represented by a
corresponding block if present.</p>

<p>A subsequent call to <a
href="Collector.html#method-i-negotiate_format">negotiate_format(request)</a>
will enable the <a href="Collector.html">Collector</a> to determine which
specific mime-type it should respond with for the current request, with
this response then being accessible by calling <a
href="Collector.html#method-i-response">response</a>.</p>

    </div>
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>A</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Collector.html#method-i-all">all</a>,
              </li>
            
              
              <li>
                <a href="Collector.html#method-i-any">any</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>C</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Collector.html#method-i-custom">custom</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>N</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Collector.html#method-i-negotiate_format">negotiate_format</a>,
              </li>
            
              
              <li>
                <a href="Collector.html#method-c-new">new</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>R</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Collector.html#method-i-response">response</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  
    <!-- Includes -->
    <div class="sectiontitle">Included Modules</div>
    <ul>
      
        <li>
          
            <a href="../../AbstractController/Collector.html">
              AbstractController::Collector
            </a>
          
        </li>
      
    </ul>
  



  

    

    

    


    
      <!-- Section attributes -->
      <div class="sectiontitle">Attributes</div>
      <table border='0' cellpadding='5'>
        
          <tr valign='top'>
            <td class='attr-rw'>
              [RW]
            </td>
            <td class='attr-name'>format</td>
            <td class='attr-desc'></td>
          </tr>
        
          <tr valign='top'>
            <td class='attr-rw'>
              [RW]
            </td>
            <td class='attr-name'>order</td>
            <td class='attr-desc'></td>
          </tr>
        
      </table>
    


    <!-- Methods -->
    
      <div class="sectiontitle">Class Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-c-new">
            
              <b>new</b>(mimes)
            
            <a href="Collector.html#method-c-new" name="method-c-new" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-new_source')" id="l_method-c-new_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/149e3cd376caa23cf4d8c4b711b95e157186fc94/actionpack/lib/action_controller/metal/mime_responds.rb#L402" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-new_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_controller/metal/mime_responds.rb, line 402</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">initialize</span>(<span class="ruby-identifier">mimes</span>)
  <span class="ruby-ivar">@order</span>, <span class="ruby-ivar">@responses</span> = [], {}
  <span class="ruby-identifier">mimes</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">mime</span><span class="ruby-operator">|</span> <span class="ruby-identifier">send</span>(<span class="ruby-identifier">mime</span>) }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                  
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-all">
            
              <b>all</b>(*args, &amp;block)
            
            <a href="Collector.html#method-i-all" name="method-i-all" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-any">
            
              <b>any</b>(*args, &amp;block)
            
            <a href="Collector.html#method-i-any" name="method-i-any" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
            <div class="aka">
              Also aliased as: <a href="Collector.html#method-i-all">all</a>
            </div>
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-any_source')" id="l_method-i-any_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/149e3cd376caa23cf4d8c4b711b95e157186fc94/actionpack/lib/action_controller/metal/mime_responds.rb#L407" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-any_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_controller/metal/mime_responds.rb, line 407</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">any</span>(*<span class="ruby-identifier">args</span>, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">any?</span>
    <span class="ruby-identifier">args</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">type</span><span class="ruby-operator">|</span> <span class="ruby-identifier">send</span>(<span class="ruby-identifier">type</span>, &amp;<span class="ruby-identifier">block</span>) }
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">custom</span>(<span class="ruby-constant">Mime</span><span class="ruby-operator">::</span><span class="ruby-constant">ALL</span>, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-custom">
            
              <b>custom</b>(mime_type, &amp;block)
            
            <a href="Collector.html#method-i-custom" name="method-i-custom" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-custom_source')" id="l_method-i-custom_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/149e3cd376caa23cf4d8c4b711b95e157186fc94/actionpack/lib/action_controller/metal/mime_responds.rb#L416" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-custom_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_controller/metal/mime_responds.rb, line 416</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">custom</span>(<span class="ruby-identifier">mime_type</span>, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-identifier">mime_type</span> = <span class="ruby-constant">Mime</span><span class="ruby-operator">::</span><span class="ruby-constant">Type</span>.<span class="ruby-identifier">lookup</span>(<span class="ruby-identifier">mime_type</span>.<span class="ruby-identifier">to_s</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">mime_type</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Mime</span><span class="ruby-operator">::</span><span class="ruby-constant">Type</span>)
  <span class="ruby-ivar">@order</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">mime_type</span>
  <span class="ruby-ivar">@responses</span>[<span class="ruby-identifier">mime_type</span>] <span class="ruby-operator">||=</span> <span class="ruby-identifier">block</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-negotiate_format">
            
              <b>negotiate_format</b>(request)
            
            <a href="Collector.html#method-i-negotiate_format" name="method-i-negotiate_format" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-negotiate_format_source')" id="l_method-i-negotiate_format_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/149e3cd376caa23cf4d8c4b711b95e157186fc94/actionpack/lib/action_controller/metal/mime_responds.rb#L426" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-negotiate_format_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_controller/metal/mime_responds.rb, line 426</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">negotiate_format</span>(<span class="ruby-identifier">request</span>)
  <span class="ruby-ivar">@format</span> = <span class="ruby-identifier">request</span>.<span class="ruby-identifier">negotiate_mime</span>(<span class="ruby-identifier">order</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-response">
            
              <b>response</b>()
            
            <a href="Collector.html#method-i-response" name="method-i-response" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-response_source')" id="l_method-i-response_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/149e3cd376caa23cf4d8c4b711b95e157186fc94/actionpack/lib/action_controller/metal/mime_responds.rb#L422" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-response_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_controller/metal/mime_responds.rb, line 422</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">response</span>
  <span class="ruby-ivar">@responses</span>.<span class="ruby-identifier">fetch</span>(<span class="ruby-identifier">format</span>, <span class="ruby-ivar">@responses</span>[<span class="ruby-constant">Mime</span><span class="ruby-operator">::</span><span class="ruby-constant">ALL</span>])
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    